<template>
	<view class="content">
		<view class="">
			<sy v-if="current == 0"></sy>
			<!-- <shop v-if="current == 1"></shop>
			<school ref="school" v-if="current == 2"></school> -->
			<my v-if="current == 1"></my>
		</view>
		<u-tabbar v-model="current" bgColor="#444444" activeColor="#C49266" inactiveColor="#C49266" :list="tabbarList" @change="selectNav" :before-switch="beforeSwitch"></u-tabbar>
	</view>
</template>

<script>
	import sy from '@/components/index/index.vue' // 首页
	import shop from '@/components/shop/shop.vue' // 商城
	import school from '@/components/school/school.vue' // 商学院
	import my from '@/components/my/my.vue' // 我的
	import {url} from "@/common/index.js"
	import {getIcon} from '@/common/api.js'
	export default {
		components: {
			sy,
			shop,
			school,
			my
		},
		data() {
			return {
				tabbarList: [{
						iconPath: "home",
						selectedIconPath: "home-fill",
						text: '首页',
					},
					{
						iconPath: "photo",
						selectedIconPath: "photo-fill",
						text: '商城',
					},
					{
						iconPath: "play-right",
						selectedIconPath: "play-right-fill",
						text: '商学院',
					},
					{
						iconPath: "account",
						selectedIconPath: "account-fill",
						text: '我的',
					}
				],
				current: 0
			}
		},
		onShow() {
				if(this.current == 2) this.$refs.school.getVideo()
				wx.showShareMenu({
									 withShareTicket: true,
									  menus: ['shareAppMessage', 'shareTimeline']
								})
		},
		methods: {
			selectNav(data) {
				this.current = data
			},
			beforeSwitch(index) {
				// 返回一个promise
				return new Promise((resolve, reject) => {
					if (index == 3 && !uni.getStorageSync("userInfo")) {
						uni.reLaunch({
							url: "/pages/login/login"
						})
						reject()
					}
					resolve()
				})
			},
			
			async getIcon(){
				let data = await getIcon(0)
				this.tabbarList = data.rows.map(res=>{
					return {
						text:res.icName,
						iconPath:url+res.icUrl,
						selectedIconPath:url+res.icUrl
					}
				})
			}
		},
		onLoad(data) {
			this.getIcon()
			if(data?.type) this.current = 3
		}
	}
</script>

<style scoped>

</style>